package com.coffeeloversupportlibrary.coffeelover.domain.coffeebean;

import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.coffeeloversupportlibrary.R;
import com.coffeeloversupportlibrary.coffeelover.domain.coffeebean.adapter.BeanMainAdapter;
import com.coffeeloversupportlibrary.core.base.BaseFragment;
import com.coffeeloversupportlibrary.databinding.BeansFragmentBinding;

/**
 * @author puyv
 * @createTime 2021/11/12 13:16
 * @projectName CoffeeLoverSupportLibrary
 * @className BeansFragment.java
 * @description TODO   作废该模块
 */
public class BeansFragment extends BaseFragment<BeansViewModel, BeansFragmentBinding> {
    private int status;
    @Override
    public void registerUIChangeCallBack() {
        getViewModel().getLoadData().observe(this, new Observer<BeanMainAdapter>() {
            @Override
            public void onChanged(BeanMainAdapter beanMainAdapter) {
                if(beanMainAdapter!=null){
                    //  写到这里 突然想到之前在主页面切换 Fragment 时，出现的问题，是不是 FragmentManager 的问题？？
                    beanMainAdapter.rebuild(getChildFragmentManager());
                    getBinding().beansRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
                    getBinding().beansRecyclerView.setAdapter(beanMainAdapter);
                }
            }
        });

    }

    @Override
    public int getLayoutId() {
        return R.layout.beans_fragment;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        status=1;

        getViewModel().init();
        getBinding().categoryHeader.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if(status==1){
                    Toast.makeText(getContext(),"别摸了，还没完成开发呢",Toast.LENGTH_SHORT).show();
                    status++;
                }else{
                    Toast.makeText(getContext(),"你还点！·",Toast.LENGTH_SHORT).show();
                }
                return true;
            }
        });
    }
}
